package com.XinYun.Library.modules.send;

import com.XinYun.Library.modules.display.response.ResponseWrapper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

@WebServlet(name = "sendemailServlet", value = "/sendemailServlet")
public class sendemailServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();
        String readerLine = reader.readLine();
        JSONObject jsonObject = JSON.parseObject(readerLine);
        String mail = jsonObject.getString("Admain_mail");

        HttpSession session = request.getSession();

        //服务器通知浏览器不要缓存
        response.setHeader("pragma","no-cache");
        response.setHeader("cache-control","no-cache");
        response.setHeader("expires","0");


        //实例化一个发送邮件的对象
        EmailUtil emailUtil = new EmailUtil();
        //发送邮件
        emailUtil.giveRcode(mail, "该同学已借阅此书");
        ResponseWrapper responseWrapper = null;
        responseWrapper = ResponseWrapper.successsend();
        String s = JSON.toJSONString(responseWrapper);
        PrintWriter writer = response.getWriter();
        writer.println(s);
        System.out.println(s);
    }
}



